﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DSLisp.Infrastructure
{
    public delegate object LazyValueDelegate();

    public class LazyValue
    {
        private LazyValueDelegate del;
        private bool evaluated = false;
        private object result = null;
        public LazyValue(LazyValueDelegate del)
        {
            this.del = del;
        }

        public object Eval()
        {
            if (!evaluated)
            {
                evaluated = true;
                result = del();                
            }

            return result;
        }

        
        public override string ToString()        
        {
            if (evaluated)
                return string.Format("{0}", result);
            else
                return "LazyValue";
        }
    }

    public class TailRecursionValue
    {
        private object expression;
        public object Expression
        {
            get
            {
                return expression;
            }
        }

        public TailRecursionValue(object expression)
        {
            this.expression = expression;
        }
    }

    //public class TailRecursionValue : LazyValue 
    //{
    //    public TailRecursionValue(LazyValueDelegate del) :base (del)
    //    {

    //    }
    //}
}
